package com.dingli.shop.biz;

import com.dingli.shop.dao.TUserMapper;
import com.dingli.shop.entity.TUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoginBiz {
    @Autowired
    private TUserMapper user;

    /**
     *
     * @param email  邮箱
     * @return   -1表示传递过来的参数有问题  0表示没有重复邮箱
     */
    public int checkEmail(String email){
        if(email != null && !email.equals("")){//检查，万一为空，后面会出现异常。 程序健壮性的体现
            try{
                int i = user.checkEmail(email);
                return i;
            }catch (Exception e){
                return -2;
            }
        }else {
            return -1;
        }
    }

    //插入到数据库
    public int insertUser(TUser tuser){

        return user.insert(tuser);
    }

    /**
     *
     * @param tuser  登录的用户
     * @return
     */
    public int login(TUser tuser){
        try{
            return  user.login(tuser);
        }catch (Exception e){
            return -1;
        }
    }

}
